//
//  CategoryEvents.swift
//  MusicApp
//
//  Created by tianjs on 2023/4/18.
//

import SwiftUI

struct CategoryEvents: View {
    
    @State private var isShowEventSave: Bool = false
    
    var body: some View {
        NavigationView {
            ZStack {
                ScrollView {
                    Text("Ed Sheeran:+-=/x Tour")
                        .font(.headline)
                        .fontWeight(.black)
                    HStack(alignment: .top) {
                        VStack(alignment: .leading) {
                            Text("Date")
                                .font(.headline)
                            .fontWeight(.black)
                            Text("2023-09-16")
                                .font(.callout)
                                .foregroundColor(.secondary)
                        }
                        
                        Spacer()
                        
                        VStack(alignment: .trailing) {
                            Text("Artist|Team")
                                .font(.headline)
                            .fontWeight(.black)
                            Text("Ed SheeranRussMaisie Peters")
                                .font(.callout)
                                .foregroundColor(.secondary)
                        }
                    }
                    .padding(.top, 0.3)
                    
                    HStack(alignment: .top) {
                        VStack(alignment: .leading) {
                            Text("Venue")
                                .font(.headline)
                            .fontWeight(.black)
                            Text("Levi'@Stadium")
                                .font(.callout)
                                .foregroundColor(.secondary)
                        }
                        
                        Spacer()
                        
                        VStack(alignment: .trailing) {
                            Text("Genre")
                                .font(.headline)
                            .fontWeight(.black)
                            Text("Music|Pop|Pop")
                                .font(.callout)
                                .foregroundColor(.secondary)
                        }
                    }
                    .padding(.top, 0.3)
                    
                    HStack(alignment: .top) {
                        VStack(alignment: .leading) {
                            Text("Price Range")
                                .font(.headline)
                            .fontWeight(.black)
                            Text("249.0~159.0")
                                .font(.callout)
                                .foregroundColor(.secondary)
                        }
                        
                        Spacer()
                        
                        VStack(alignment: .trailing) {
                            Text("Ticket Status")
                                .font(.headline)
                            .fontWeight(.black)
                            Button {
                                    
                            } label: {
                                Text("Onsale")
                                    .padding([.leading, .trailing], 15)
                                    .padding([.top, .bottom], 5)
                            }
                            .foregroundColor(.white)
                            .background(Color(.systemGreen))
                            .cornerRadius(4)
                            
                        }
                    }
                    .padding(.top, 0.3)
                    
                    let round = Int.random(in: 0..<2)
                    
                    if (round % 2 == 0) {
                        NavigationLink(isActive: $isShowEventSave, destination: {
                            EventSearch()
                        }, label: {
                            
                        })

                        Button {
                            isShowEventSave = true
                        } label: {
                            Text("Remove Favorite")
                                .padding([.top, .bottom], 15)
                                .padding([.leading, .trailing], 20)
                                .frame(width: 140, height: 50)
                        }
                        .background(Color(.systemRed))
                        .foregroundColor(.white)
                    .cornerRadius(15)
                    } else {
                        NavigationLink(isActive: $isShowEventSave, destination: {
                            EventSearch()
                        }, label: {
                            
                        })
                        
                        Button {
                            isShowEventSave = true
                        } label: {
                            Text("Save Event")
                                .padding([.top, .bottom], 15)
                                .padding([.leading, .trailing], 20)
                                .frame(height: 50)
                        }
                        .background(Color(.systemBlue))
                        .foregroundColor(.white)
                        .cornerRadius(15)
                    }
                    
                    Image(systemName: "seal.fill")
                        .resizable()
                        .frame(width: 200,height: 200)
                        .background(Color(.systemBlue))
                        .cornerRadius(20)
                        .padding([.top, .bottom], 20)
                    
                    HStack {
                        Text("Buy Ticket At:")
                            .foregroundColor(.black)
                            .fontWeight(.black)
                        Button {
                            
                        } label: {
                            Text("Ticketmaster")
                        }
                    }
                    
                    HStack {
                        Text("Share on:")
                            .foregroundColor(.black)
                            .fontWeight(.black)
                        
                        Button {
                            
                        } label: {
                            Image("f_logo_RGB-Blue_144")
                                .resizable()
                                .renderingMode(.original)
                                .frame(width: 40, height: 40)
                        }

                        Button {
                            
                        } label: {
                            Image("Twitter social icons - circle - blue")
                                .resizable()
                                .renderingMode(.original)
                                .frame(width: 40, height: 40)
                        }

                    }

                }
                .padding([.leading, .trailing], 15)
                
                let showPop = Int.random(in: 0..<2)
                if (showPop % 2 == 0) {
                    ZStack(alignment: .bottom) {
                        VStack {
                            Text("Added to favorites")
                                .font(.footnote)
                                .foregroundColor(.black)
                        }
                        .frame(minWidth: 80, idealWidth: 120, maxWidth: 300, minHeight: 100, maxHeight: 100, alignment: .center)
                        .background(Color(.systemGray))
                        .shadow(color: .gray, radius: 6, x: 0, y: 0)
                        .opacity(0.7)
                        .cornerRadius(15)
                        .offset(y:200)
                        .padding(.bottom, -200)
                    }
                }
            }
            .navigationBarHidden(true)
            .navigationTitle("")
        }
    }
}

struct CategoryEvents_Previews: PreviewProvider {
    static var previews: some View {
        CategoryEvents()
    }
}
